﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="UserManage.aspx.cs" Inherits="GH.Web.SystemManage.UserManage1" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>欢迎使用工会管理系统</title>
    <link href="../style/main.css" rel="stylesheet" type="text/css" />
    <link rel="stylesheet" type="text/css" href="../css/css.css" />
    <link rel="stylesheet" type="text/css" href="/css/jquery-ui-1.7.2.custom.css" />
    <link rel="stylesheet" type="text/css" href="../JqueryUI/themes/ui-lightness/jquery-ui-1.7.2.custom.css" />

    <script type="text/javascript" src="../javascript/jquery-1.3.2.js"></script>

    <script type="text/javascript" src="../javascript/jquery-ui-1.7.2.custom.js"></script>

    <script type="text/javascript" src="../javascript/messageBox.js"></script>

    <script type="text/javascript" src="../javascript/formValidator.js"></script>

    <script type="text/javascript" src="../javascript/formValidatorRegex.js"></script>

    <script type="text/javascript" src="../javascript/Public.js"></script>

    <script type="text/javascript" language="javascript">

        function isExist() {


            var queryString = "";
            var FormFlg = "USER"; //处理画面区分，对应不同的后台业务处理                
            var strName = $("#txtUserID").val();

            queryString = "FormFlg=" + FormFlg
                               + "&strName=" + strName
                               + "&id=" + $("#txtID").val();
            $.ajax
                        ({
                            async: false,
                            type: "post", //ajax请求方式
                            url: "../AjaxExist.aspx", //请求服务器地址
                            datatype: "json", //希望数据库返回的数据类型
                            data: queryString, //发送给服务器的数据
                            processData: false, //阻止数据被自动转换为url编码
                            success: function(data) {//请求成功则调用该函数
                                if (data == "1") {
                                    $("#txtState").val("");
                                    alert("会员已存在！");
                                    return;
                                } else {
                                    $("#txtState").val("OK");
                                    return;
                                }
                            }
                        });

        }


        $(document).ready(function() {

            var formValid = false; //表单验证是否成功flg
            jQuery.formValidator.initConfig({ validatorgroup: "1", tidymode: false, forcevalid: false, alertmessage: false, errorfocus: true, onerror: function(msg) { alert(msg) }, onsuccess: function() { formValid = true; return true; } });

            //用户名  txtUserID
            jQuery("#txtUserID").formValidator({ validatorgroup: "1", empty: false })//不可省略
                                 .functionValidator({ fun: isemptycheck, onerror: ShowMessage("用户名", "1001") })//不可省略check
                                    .inputValidator({ min: 1, max: 12, onerror: ShowMessage("用户名", "1005") })

            //登录密码  txtPassword
            jQuery("#txtPassword").formValidator({ validatorgroup: "1", empty: false })//不可省略
                                 .functionValidator({ fun: isemptycheck, onerror: ShowMessage("登录密码", "1001") })//不可省略check
                                    .inputValidator({ min: 1, max: 12, onerror: ShowMessage("登录密码", "1005") })

            //确认密码 txtRePassword
            jQuery("#txtRePassword").formValidator({ validatorgroup: "1", empty: false })//不可省略
                                 .functionValidator({ fun: isemptycheck, onerror: ShowMessage("部门代码", "1001") })//不可省略check
                                    .inputValidator({ min: 1, max: 12, onerror: ShowMessage("部门代码", "1005") })

            $("#txtState").formValidator({ validatorgroup: "1", empty: false })
	                     .inputValidator({ min: 1, max: 2, onerror: ShowMessage("会员", "1038") })



            $("#ShowDiag").dialog({
                bgiframe: true,
                autoOpen: false,
                height: 340,
                modal: true,
                draggable: true,
                buttons: {
                    '提交': function() {
                        jQuery.formValidator.pageIsValid('1');
                        if (!formValid) {
                            return false;
                        }
                        if (Update(btnName)) {
                            $(this).dialog('close');
                            var submitForm = document.getElementById("mainForm");
                            submitForm.submit();
                        }
                    },
                    '取消': function() {
                        $(this).dialog('close');
                    }
                },
                close: function() {
                    $("#txtDepartMentID").val("");
                    $("#ddlUion").empty();
                    $("#ddlDepartment").empty();
                    $("#ddlRole").empty();
                    //单位
                    GetUionList();
                    //角色
                    GetRoleList();
                }
            });
            //处理区分
            var btnName = "";
            function createQueryString() {
                var queryString = "";
                var UpdateFlg = btnName; //操作区分，更新或者新规
                var FormFlg = "USER"; //处理画面区分，对应不同的后台业务处理
                queryString = "FormFlg=" + FormFlg
                                + "&UpdateFlg=" + UpdateFlg
                                + "&ID=" + $("#txtID").val()
                                + "&UserID=" + $("#txtUserID").val()
                                + "&Uion=" + $("#ddlUion").val()
                                + "&Department=" + $("#ddlDepartment").val()
                                + "&Role=" + $("#ddlRole").val()
                                + "&Password=" + $("#txtPassword").val()
                                + "&UseState=" + $("#ddlUseState").val()
                               ;
                return queryString;
            }

            function Update(operflg) {
                var addValid = false; //插入操作是否成功flg
                $.ajax
                        ({
                            async: false,
                            type: "post", //ajax请求方式
                            url: "../ajaxUpdate.aspx", //请求服务器地址
                            datatype: "json", //希望数据库返回的数据类型
                            data: createQueryString(), //发送给服务器的数据
                            processData: false, //阻止数据被自动转换为url编码
                            success: function(data) {//请求成功则调用该函数
                                if (data == "OK") {
                                    addValid = true;
                                    if (operflg == "Add") {
                                        alert("登录成功！")
                                    }
                                    else if (operflg == "Update") {
                                        alert("更新成功！")
                                    }
                                    var submitForm = document.getElementById("mainForm");
                                    submitForm.submit();
                                }
                                else {
                                    addValid = false;
                                    if (operflg == "Add") {
                                        alert("登录失败！")
                                    }
                                    else if (operflg == "Update") {
                                        alert("更新失败！")
                                    }
                                }
                            }
                        });
                return addValid;
            };

            $("#btnAdd").click(function() {
                btnName = "Add";
                $("#ShowDiag").dialog('open');
            });

            $(".btnUpdate").click(function() {
                btnName = "Update";
                $('#txtID').val($.trim($(this).parent().find('td:eq(0)').text()));
                $('#txtUserID').val($.trim($(this).parent().find('td:eq(1)').text()));
                $('#txtUserName').val($.trim($(this).parent().find('td:eq(2)').text()));
                $('#ddlUion').val($.trim($(this).parent().find('td:eq(3)').text()));
                $('#ddlDepartment').val($.trim($(this).parent().find('td:eq(5)').text()));
                $('#ddlRole').val($.trim($(this).parent().find('td:eq(6)').text()));
                $('#txtPassword').val($.trim($(this).parent().find('td:eq(10)').text()));
                $('#txtRePassword').val($.trim($(this).parent().find('td:eq(10)').text()));
                $('#ddlUseState').val($.trim($(this).parent().find('td:eq(8)').text()));
                $("#ShowDiag").dialog('open');
            });

            jQuery(".btnDelete").click(function() {
                var queryString = "";
                var FormFlg = "USER"; //处理画面区分，对应不同的后台业务处理
                var UpdateFlg = "Delete";   //操作区分，更新或者新规
                var ID = jQuery.trim(jQuery(this).parent().find('td:eq(0)').text());
                queryString = "FormFlg=" + FormFlg
                               + "&UpdateFlg=" + UpdateFlg
                               + "&ID=" + ID;
                jQuery.ajax
                        ({
                            async: false,
                            type: "post", //ajax请求方式
                            url: "../ajaxUpdate.aspx", //请求服务器地址
                            datatype: "json", //希望数据库返回的数据类型
                            data: queryString, //发送给服务器的数据
                            processData: false, //阻止数据被自动转换为url编码
                            success: function(data) {//请求成功则调用该函数
                                if (data == "OK") {
                                    alert("删除成功！");
                                    var submitForm = document.getElementById("mainForm");
                                    submitForm.submit();
                                } else {

                                    alert("删除失败！");
                                }
                            }
                        });

            });
            //下拉列表联动
            //单位
            GetUionList();
            //角色
            GetRoleList();
            $("#ddlUion").change(function() {
                GetDepartmentList();
            });

            //加载单位相应的选项
            function GetUionList() {
                $("#ddlUion").empty(); //清空业务SELECT控件

                var queryString = "time=" + new Date() + "&TransFlg=UionList";
                $.ajax
                    ({
                        async: false,
                        type: "post", //ajax请求方式
                        url: "../ajaxGetJason.aspx", //请求服务器地址
                        datatype: "json", //希望数据库返回的数据类型
                        data: queryString, //发送给服务器的数据
                        processData: false, //阻止数据被自动转换为url编码
                        success: function(data) {//请求成功则调用该函数
                            var temp = eval(data);
                            if (temp) {
                                $.each(temp, function(i, item) {
                                    $("<option></option>")
                                   .val(item["ID"])
                                   .text(item["单位名称"])
                                   .appendTo($("#ddlUion"));
                                });
                            }
                        }
                    });
                GetDepartmentList();
            }
            //加载部门相应的选项
            function GetDepartmentList() {
                $("#ddlDepartment").empty(); //清空业务SELECT控件
                //                $("<option></option>")
                //                            .val("")
                //                            .text("")
                //                            .appendTo($("#ddlDepartment"));
                var queryString = "time=" + new Date() + "&TransFlg=DepartmentList" + "&UionID=" + $("#ddlUion").val();
                $.ajax
                    ({
                        async: false,
                        type: "post", //ajax请求方式
                        url: "../ajaxGetJason.aspx", //请求服务器地址
                        datatype: "json", //希望数据库返回的数据类型
                        data: queryString, //发送给服务器的数据
                        processData: false, //阻止数据被自动转换为url编码
                        success: function(data) {//请求成功则调用该函数
                            var temp = eval(data);
                            if (temp) {

                                $.each(temp, function(i, item) {
                                    $("<option></option>")
                            .val(item["ID"])
                            .text(item["部门名称"])
                            .appendTo($("#ddlDepartment"));
                                });
                            }
                        }
                    });
            }
            //加载角色相应的选项
            function GetRoleList() {
                $("#ddlRole").empty(); //清空业务SELECT控件
                var queryString = "time=" + new Date() + "&TransFlg=RoleList";
                $.ajax
                    ({
                        async: false,
                        type: "post", //ajax请求方式
                        url: "../ajaxGetJason.aspx", //请求服务器地址
                        datatype: "json", //希望数据库返回的数据类型
                        data: queryString, //发送给服务器的数据
                        processData: false, //阻止数据被自动转换为url编码
                        success: function(data) {//请求成功则调用该函数
                            var temp = eval(data);
                            if (temp) {

                                $.each(temp, function(i, item) {
                                    $("<option></option>")
                            .val(item["角色ID"])
                            .text(item["角色名称"])
                            .appendTo($("#ddlRole"));
                                });
                            }
                        }
                    });
            }
        });
    </script>

    <style type="text/css">
        .style1
        {
            color: #FF0066;
        }
    </style>
</head>
<body>
    <form id="mainForm" runat="server">
    <input type="hidden" id="txtState" value="OK" />
    <table width="100%" cellpadding="0" cellspacing="0">
        <tr>
            <td>
                <table width="99%" cellpadding="0" cellspacing="0" class="table">
                    <tr>
                        <td valign="top">
                            <table width="100%" class="top" cellpadding="0" cellspacing="0">
                                <tr>
                                    <td style="height: 22px;">
                                        &nbsp;<b>当前位置:</b>&nbsp;<a href="#">系统管理</a>&nbsp;>>&nbsp;<a href="#">用户管理</a>
                                    </td>
                                </tr>
                            </table>
                        </td>
                    </tr>
                    <tr>
                        <td style="height: 5px">
                        </td>
                    </tr>
                    <tr>
                        <td align="right" valign="middle" style="border: thin dotted #C0C0C0; background-color: #C5E5FC">
                            <img alt="" src="../images/submit.gif" id="btnAdd" />
                            &nbsp;&nbsp;
                        </td>
                    </tr>
                    <tr>
                        <td style="height: 5px">
                        </td>
                    </tr>
                    <tr>
                        <td valign="top">
                            <table style="width: 100%; background-color: Silver" cellpadding="1px" cellspacing="1px">
                                <tr>
                                    <th style="height: 22px; background-color: #B2DBF7; display: none;">
                                        用户ID
                                    </th>
                                    <th style="height: 22px; background-color: #B2DBF7">
                                        用户名
                                    </th>
                                    <th style="height: 20px; background-color: #B2DBF7; display: none;">
                                        单位ID
                                    </th>
                                    <th style="height: 20px; width: 30%; background-color: #B2DBF7">
                                        单位
                                    </th>
                                    <th style="height: 20px; background-color: #B2DBF7; display: none;">
                                        部门ID
                                    </th>
                                    <th style="height: 20px; width: 30%; background-color: #B2DBF7">
                                        部门
                                    </th>
                                    <th style="height: 20px; background-color: #B2DBF7; display: none;">
                                        角色ID
                                    </th>
                                    <th style="height: 20px; background-color: #B2DBF7">
                                        角色
                                    </th>
                                    <th style="height: 20px; background-color: #B2DBF7; display: none;">
                                        启用状态
                                    </th>
                                    <th style="height: 20px; background-color: #B2DBF7">
                                        启用状态
                                    </th>
                                    <th style="height: 20px; background-color: #B2DBF7" colspan="2">
                                        操作
                                    </th>
                                </tr>
                                <asp:Repeater ID="rptList" runat="server">
                                    <HeaderTemplate>
                                    </HeaderTemplate>
                                    <ItemTemplate>
                                        <tr>
                                            <td style="height: 22px; background-color: #FFFFFF; display: none;">
                                                <%# DataBinder.Eval(Container.DataItem, "ID")%>
                                            </td>
                                            <td style="height: 22px; background-color: #FFFFFF;">
                                                <%# DataBinder.Eval(Container.DataItem, "用户ID")%>
                                            </td>
                                            <td style="height: 22px; background-color: #FFFFFF; display: none;">
                                                <%# DataBinder.Eval(Container.DataItem, "单位")%>
                                            </td>
                                            <td style="height: 22px; width: 30%; background-color: #FFFFFF">
                                                <%# DataBinder.Eval(Container.DataItem, "单位名称")%>
                                            </td>
                                            <td style="height: 22px; background-color: #FFFFFF; display: none;">
                                                <%# DataBinder.Eval(Container.DataItem, "部门")%>
                                            </td>
                                            <td style="height: 22px; width: 30%; background-color: #FFFFFF">
                                                <%# DataBinder.Eval(Container.DataItem, "部门名称")%>
                                            </td>
                                            <td style="height: 22px; background-color: #FFFFFF; display: none;">
                                                <%# DataBinder.Eval(Container.DataItem, "角色ID")%>
                                            </td>
                                            <td style="height: 22px; background-color: #FFFFFF">
                                                <%# DataBinder.Eval(Container.DataItem, "角色名称")%>
                                            </td>
                                            <td style="height: 22px; background-color: #FFFFFF; display: none;">
                                                <%# DataBinder.Eval(Container.DataItem, "启用状态")%>
                                            </td>
                                            <td style="height: 22px; background-color: #FFFFFF">
                                                <%# DataBinder.Eval(Container.DataItem, "启用状态名称")%>
                                            </td>
                                            <td style="height: 22px; background-color: #FFFFFF; display: none;">
                                                <%# DataBinder.Eval(Container.DataItem, "登陆密码")%>
                                            </td>
                                            <td style="height: 22px; background-color: #FFFFFF; text-align: center; cursor: pointer;"
                                                class="btnUpdate">
                                                编辑
                                            </td>
                                            <td style="height: 22px; background-color: #FFFFFF; text-align: center; cursor: pointer"
                                                class="btnDelete">
                                                删除
                                            </td>
                                        </tr>
                                    </ItemTemplate>
                                    <FooterTemplate>
                                        </table>
                                    </FooterTemplate>
                                </asp:Repeater>
                        </td>
                    </tr>
                </table>
            </td>
        </tr>
    </table>
    <div id="ShowDiag" title="追加用户">
        <fieldset>
            <table>
                <tr style="display: none;">
                    <td align="right">
                        ID
                    </td>
                    <td>
                        <input type="text" name="txtID" id="txtID" />
                    </td>
                </tr>
                <tr>
                    <td align="right">
                        用户名
                    </td>
                    <td>
                        <input type="text" name="txtUserID" id="txtUserID" maxlength="12" style="width: 100px"
                            onchange="isExist()" /><span class="style1">*</span>
                    </td>
                </tr>
                <tr>
                    <td align="right">
                        单位
                    </td>
                    <td>
                        <asp:DropDownList ID="ddlUion" runat="server">
                        </asp:DropDownList>
                        <span class="style1">*</span>
                    </td>
                </tr>
                <tr>
                    <td align="right">
                        部门
                    </td>
                    <td>
                        <asp:DropDownList ID="ddlDepartment" runat="server">
                        </asp:DropDownList>
                    </td>
                </tr>
                <tr>
                    <td align="right">
                        角色
                    </td>
                    <td>
                        <asp:DropDownList ID="ddlRole" runat="server">
                        </asp:DropDownList>
                    </td>
                </tr>
                <tr>
                    <td align="left">
                        登录密码
                    </td>
                    <td>
                        <input type="password" name="txtPassword" id="txtPassword" maxlength="12" style="width: 100px" /><span
                            class="style1">*</span>
                    </td>
                </tr>
                <tr>
                    <td align="left">
                        确认密码
                    </td>
                    <td>
                        <input type="password" name="txtRePassword" id="txtRePassword" maxlength="12" style="width: 100px" /><span
                            class="style1">*</span>
                    </td>
                </tr>
                <tr>
                    <td align="left">
                        启用状态
                    </td>
                    <td>
                        <asp:DropDownList ID="ddlUseState" runat="server">
                            <asp:ListItem Selected="True" Value="1" Text="可使用"></asp:ListItem>
                            <asp:ListItem Value="0" Text="不可使用"></asp:ListItem>
                        </asp:DropDownList>
                        <span class="style1">*</span>
                    </td>
                </tr>
            </table>
        </fieldset>
    </div>

    <script type="text/javascript">
        $("#ShowDiag").hide();
    </script>

    </form>
</body>
</html>
